package com.bdqn.springbootmybatisplus;

import org.apache.log4j.Logger;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * RedisService
 *
 * @author f
 * @since 2021/12/11
 */
@Service("redisService")
public class RedisService {
    private Logger logger = Logger.getLogger(RedisService.class);
    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 封装简单插入操作
     */
    public boolean set(final String key, Object value) {
        boolean result = false;
        try {
            ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
            operations.set(key, value);
            result = true;
        } catch (Exception e) {
            logger.error("set error: key {}, value {}"+key+value,e);
        }
        return result;
    }
}
